package net.vinote.smartweb.service.impl;

import net.vinote.smartweb.dal.dao.UserInfoDAO;
import net.vinote.smartweb.service.facade.UserInfoService;
import net.vinote.smartweb.service.facade.vo.UserInfoVO;
import net.vinote.smartweb.service.result.SmartResult;
import net.vinote.smartweb.service.util.AbstractService;
import net.vinote.smartweb.service.util.SmartServiceCallback;

import org.springframework.beans.factory.annotation.Autowired;

public class UserInfoServiceImpl extends AbstractService implements
		UserInfoService {

	@Autowired
	private UserInfoDAO userInfoDao;

	public SmartResult<UserInfoVO> query(final int name) {
		final SmartResult<UserInfoVO> result = new SmartResult<UserInfoVO>();
		operateTemplate.operateWithoutTransaction(result,
				new SmartServiceCallback() {

					@Override
					public void doOperate() {
						userInfoDao.selectById(name);
						UserInfoVO vo = new UserInfoVO();
						vo.setAge((int) (Math.random() * 100));
						vo.setName("zjw" + vo.getAge());
						result.setValue(vo);
					}
				});

		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * net.vinote.smartweb.service.UserInfoService#queryCount(java.lang.String,
	 * java.lang.String)
	 */
	public SmartResult<Integer> queryCount(final int id, final String pwd) {
		final SmartResult<Integer> result = new SmartResult<Integer>();
		operateTemplate.operateWithoutTransaction(result,
				new SmartServiceCallback() {

					@Override
					public void doOperate() {
						System.out.println(userInfoDao.selectCount(id, pwd));
						result.setValue(userInfoDao.selectCount(id, pwd));
					}
				});

		return result;
	}

}
